package top.conangao.common.json.config;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.support.config.FastJsonConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 28724
 * @description
 * @since 2024/2/15 13:50
 **/
@Configuration
public class JsonConfig {
    @Bean
    public FastJsonConfig fastJsonConfig(){
        //1.自定义配置...
        FastJsonConfig config = new FastJsonConfig();
        config.setDateFormat("yyyy-MM-dd HH:mm:ss");
        //2.1配置序列化的行为
        //JSONWriter.Feature.PrettyFormat:格式化输出
        config.setWriterFeatures(JSONWriter.Feature.PrettyFormat);
        //2.2配置反序列化的行为
        config.setReaderFeatures(JSONReader.Feature.FieldBased, JSONReader.Feature.SupportArrayToBean);
        return config;
    }
    
}
